package com.koron.order.linepatrol.satellite.controller;


import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.order.linepatrol.satellite.bean.po.LinePatrolMonitor;
import com.koron.order.linepatrol.satellite.bean.query.LinePatrolMonitorQuery;
import com.koron.order.linepatrol.satellite.service.LinePatrolMonitorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 卫星监测风险工单(LinePatrolMonitor)表控制层
 *
 * @author jzp
 * @since 2023-02-08 16:47:14
 */
@Api(tags = "线路巡视-卫星监测风险工单接口")
@RestController
@RequestMapping("linePatrolMonitor")
public class LinePatrolMonitorController {
    /**
     * 服务对象
     */
    @Autowired
    private LinePatrolMonitorService linePatrolMonitorService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping("getById")
    public Response<LinePatrolMonitor> selectOne(@RequestParam String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), linePatrolMonitorService, "getById", LinePatrolMonitor.class, id));
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("page")
    public Response<PageInfo<LinePatrolMonitor>> page(PageQuery pageQuery, LinePatrolMonitorQuery query) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), linePatrolMonitorService, "page", PageInfo.class, pageQuery, query));
    }

    @ApiOperation(value = "保存")
    @PostMapping("save")
    public Response<LinePatrolMonitor> save(@RequestBody LinePatrolMonitor linePatrolMonitor) {
        ADOConnection.runTask(getCurrDs(), linePatrolMonitorService, "save", Boolean.class, linePatrolMonitor);
        return Response.ok(linePatrolMonitor);
    }


    @ApiOperation(value = "删除")
    @DeleteMapping("delete")
    public Response delete(@RequestParam String id) {
        ADOConnection.runTask(getCurrDs(), linePatrolMonitorService, "deleteById", Boolean.class, id);
        return Response.ok();
    }

}

